/*
 * Copyright 2004-2011 Paolo Conte
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jellylab.ojoverse;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.jellylab.ojoverse.types.BaseTypes;

/**
 * 
 */
public abstract class DataWrapper extends BaseTypes {
    private Map columns = new HashMap();
    private List groups = new Vector();
    private Map labels = new HashMap();

    public abstract DataObject getData();

    public abstract DataObject getWhere();

    public abstract String getSelectSQL();

    public Map getColumns() {
        return columns;
    }

    protected void column(Column col2add) {
        columns.put(col2add.name, col2add);
    }

    protected int group(String name) {
        if (!groups.contains(name)) {
            groups.add(name);
        }
        return groups.indexOf(name);
    }

    public void label(String name, String value) {
        labels.put(name, value);
    }

    public String getLabel(String name) {
        Object ret = labels.get(name);
        if (ret == null) {
            return name;
        } else {
            return (String) ret;
        }
    }

    public void setLabels(Map labels, boolean append) {
        if (append) {
            this.labels.putAll(labels);
        } else {
            this.labels = labels;
        }
    }

    public String getGroup(int idg) {
        String group = (String) groups.get(idg);
        if (group == null) {
            group = "";
        }
        return group;
    }

    public List getGroups() {
        return groups;
    }
}
